package com.tiny.mirror.service.product.domain.ability;

import com.tiny.mirror.basic.db.domain.DomainBase;
import com.tiny.mirror.service.product.domain.DomainFactory;
import com.tiny.mirror.service.product.enums.AbilityStatusEnum;
import com.tiny.mirror.service.product.enums.AbilityTypeEnum;
import com.tiny.mirror.service.product.infrastructure.entity.db.AbilityEntity;
import java.io.Serializable;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.javers.core.metamodel.annotation.Entity;
import org.javers.core.metamodel.annotation.Id;

/**
 * @Author: lanpai
 * @Description:
 * @Date: Create in 2023/9/24
 */
@Getter
@Setter
@Entity
public class Ability extends DomainBase<Long, AbilityEntity> implements Serializable {

  @Id
  private Long id = -1L;
  private String name;
  private AbilityParams params;
  private AbilityTypeEnum type;
  private AbilityStatusEnum status;
  private Integer orderNum;

  @Override
  public AbilityEntity toEntity() {
    return DomainFactory.convertToAbilityEntity(this);
  }

  @Override
  public void setIdAfterCreate(Long id) {
    this.id = id;
  }

  public void edit(Ability item) {
    if (Objects.isNull(item)) {
      return;
    }
    String name = item.getName();
    if (StringUtils.isNotEmpty(name)) {
      setName(name);
    }
    AbilityTypeEnum type = item.getType();
    if (type != null) {
      setType(type);
    }
    AbilityStatusEnum status = item.getStatus();
    if (status != null) {
      setStatus(status);
    }
    Integer orderNum = item.getOrderNum();
    if (orderNum != null) {
      setOrderNum(item.getOrderNum());
    }
  }
}